package com.roadmap.client.sns;

import java.util.List;

import com.roadmap.common.BaseConst;
import com.roadmap.exception.ServerException;
import com.roadmap.repo.db.DatabaseUtility;
import com.roadmap.repo.db.IDatabaseUtility;

public class SearchEngine implements ISearchEngine {
	private final IDatabaseUtility _dataUtil = new DatabaseUtility();

	public List retrieveFriends(String username, char sex, String currentUserId)
			throws ServerException {
		if (username == null) {
			return null;
		}

		String hql = null;
		Object[] params = null;
		if (sex != BaseConst.ASPIRANT_SEX_MALE
				&& sex != BaseConst.ASPIRANT_SEX_FEMALE) {
			hql = "from Aspirant where realName=? and aspirantId<>?";
			params = new Object[] { username, currentUserId};
		}
		else {
			hql = "from Aspirant where realName=? and sex=? and aspirantId<>?";
			params = new Object[] { username, sex, currentUserId};
		}

		return _dataUtil.executeHQLQuery(hql, params);
	}

	public List retrieveFriends(String mail, String currentUserId) throws ServerException {
		if(mail == null){
			return null;
		}
		
		String hql = "from Aspirant where mail=? and aspirantId<>?";
		Object[] params = {mail, currentUserId};
		return _dataUtil.executeHQLQuery(hql, params);
	}

}
